package com.xcdh.orm.service.ddl.impl;

import com.xcdh.orm.ddl.DDLIndex;
import com.xcdh.orm.mapper.ddl.mysql.MysqlDDLIndexMapper;
import com.xcdh.orm.service.ddl.DDLIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * OracleDDLIndexServiceImpl
 * Created by wjg on 2023/12/5.
 */
@Service("mysqlDDLIndexService")
public class MysqlDDLIndexServiceImpl implements DDLIndexService {
    @Autowired
    private MysqlDDLIndexMapper mysqlDDLIndexMapper ;

    @Override
    public List<DDLIndex> queryIndex(DDLIndex index) {
        return mysqlDDLIndexMapper.queryIndex(index);
    }

    @Override
    public int createIndex(DDLIndex index) {
        if(index.isPk()){
            return createPrimary(index) ;
        }
        return mysqlDDLIndexMapper.createIndex(index);
    }

    @Override
    public int createPrimary(DDLIndex index) {
        return mysqlDDLIndexMapper.createPrimary(index);
    }

    @Override
    public int createIndex(List<DDLIndex> indexList) {
        int count = 0 ;
        for (DDLIndex ddlIndex : indexList) {
            count += createIndex(ddlIndex) ;
        }
        return count;
    }

    @Override
    public int dropIndex(DDLIndex index) {
        return mysqlDDLIndexMapper.dropIndex(index);
    }
}
